package PriorityQueue;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;

public class UsingPriorityQueue {
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();//默认初始化11个空间,小跟堆
        priorityQueue.offer(11);
        priorityQueue.offer(22);
        priorityQueue.offer(44);
        priorityQueue.offer(55);
        priorityQueue.offer(2);
        priorityQueue.offer(8);
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());

//        List<Integer> list = new ArrayList<>();
//        list.add(1);
//        list.add(4);
//        list.add(3);
//        list.add(6);
//        list.add(2);
//        PriorityQueue<Integer> priorityQueue1 = new PriorityQueue<>(list);
//        System.out.println(priorityQueue1.poll());
//        System.out.println(priorityQueue1.poll());

        PriorityQueue<Integer> priorityQueue2 = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        priorityQueue2.offer(1);
        priorityQueue2.offer(2);
        priorityQueue2.offer(4);
        priorityQueue2.offer(3);
        priorityQueue2.offer(9);
        priorityQueue2.offer(5);
        System.out.println(priorityQueue2.poll());

        PriorityQueue<Integer> priorityQueue3 = new PriorityQueue<>((a,b)->b-a);
        priorityQueue3.offer(1);
        priorityQueue3.offer(2);
        priorityQueue3.offer(4);
        priorityQueue3.offer(3);
        priorityQueue3.offer(9);
        priorityQueue3.offer(5);
        System.out.println(priorityQueue3.poll());
    }
}
